local fengji_ag = fk.CreateSkill {
  name = "#th_fengji_ag",
}

fengji_ag:addEffect("active", {
  handly_pile = true,
  card_num = function(self, player)
    return player:getMark("@th_fengji")
  end,
  min_target_num = 1,
  card_filter = function(self, player, to_select, selected)
    return #selected < player:getMark("@th_fengji") and Fk:getCardById(to_select).color == Card.Red and Fk:currentRoom():getCardArea(to_select) ~= Card.PlayerEquip
  end,
  target_filter = function(self, player, to_select, selected, cards)
    local card = Fk:cloneCard("amazing_grace")
    card.skillName = "th_fengji"
    card:addSubcards(cards)
    return #cards >= self:getMinCardNum(player) and (table.contains(table.map(selected, Util.IdMapper), self.first_target) or to_select.id == self.first_target) and player:canUseTo(card, to_select)
  end,
  feasible = function(self, player, selected, selected_cards)
    local card = Fk:cloneCard("amazing_grace")
    card.skillName = "th_fengji"
    return table.contains(table.map(selected, Util.IdMapper), self.first_target) and #selected >= self:getMinTargetNum(player) and #selected <= card.skill:getMaxTargetNum(player, card)
    and #selected_cards >= self:getMinCardNum(player) and #selected_cards <= self:getMaxCardNum(player)
  end,
})

return fengji_ag